<?php

use Illuminate\Database\Seeder;
use App\Models\ViewCount;
use App\Models\User;
class ViewCountsTableSeeder extends Seeder
{
    public function run()
    {
        $users = User::all();
        $faker = app(Faker\Generator::class);
        $date_today = date('Y-m-d');
        $date_yestoday = date('Y-m-d', time() - 86400);
        $date_before_yestoday = date('Y-m-d', time() - 86400 - 86400);
        $data = [];
        // 为每个用户填充过去30天的数据
        foreach ($users as $user) {
            for ($i = 1; $i < 20; $i++)
            {
               $data[] = [
                    'user_id' => $user->id,
                    'date' => date('Y-m-d', time() - 86400 * $i),
                    'counts' => $faker->numberBetween(1,999999)
                ];
            }
        }
        ViewCount::insert($data);
    }

}

